<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">商户绑定</block>
		</cu-custom>
		<form>
			<u-gap height="15" bgColor="#f1f1f1"></u-gap>
			<view class="cu-form-group">
				<view class="title">当前商户</view>
				<input placeholder="" name="input" :disabled="true" v-model="merchant.name"></input>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg" @click="onSubmit">提交绑定</button>
			</view>
		</form>
		<!-- 加载弹窗 -->
		<view class="cu-load load-modal" v-if="loading">
			<!-- <view class="cuIcon-emojifill text-orange"></view> -->
			<image src="https://mini.wm-mis.com/img/static/car.png" mode="aspectFit" class="round"></image>
			<view class="gray-text">加载中...</view>
		</view>
	</view>
</template>

<script>
	import api from '@/api/api.js'
	import { mapActions, mapState } from "vuex"
	export default {
		computed: {
			...mapState([
				'merchant'
			])
		},
		data() {
			return {
				loading: false,
				minicode: null,
			};
		},
		async onLoad(options){
			this.minicode = options.minicode
		},
		methods: {
			async onSubmit() {
				let that = this
				that.loading = true
				let res = await api.shopBindMiniCode({
					shopid: this.merchant.id,
					minicode: this.minicode
				})
				if(res.data.code == 200 && res.data.success){
					uni.showToast({
						title: '操作成功',
						icon: 'success',
						duration: 2000
					})
					
					that.loading = false
					setTimeout(()=>{
						uni.navigateBack();
					}, 2000)
				}
				that.loading = false
			}
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>